#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
using namespace std;

int cal(vector<tuple<int, int, int>> &func, int i, int x)
{
	auto [a, b, c] = func[i];
	return a * x * x + b * x + c;
}

void method_tuple(int n, int m)
{
	vector<tuple<int, int, int>> func;
	for (int i = 0, a, b, c; i < n; i++) {
		cin >> a >> b >> c;
		func.emplace_back(a, b, c);
	}

	auto cmp = [](auto &a, auto &b) { return get<0>(a) > get<0>(b); };
	priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, decltype(cmp)> pq(cmp);
	for (int i = 0; i < n; i++) {
		pq.push({ cal(func, i, 1), i, 1 });
	}

	vector<int> ans;
	while (m > 0) {
		auto [val, id, x] = pq.top();
		pq.pop();

		ans.push_back(val);
		pq.emplace(cal(func, id, x + 1), id, x + 1);
		m--;
	}

	for (auto val : ans) {
		cout << val << ' ';
	}
	cout << endl;
}

void method_vector(int n, int m)
{
	vector<vector<int>> func(n, vector<int>(3, 0));

	auto cmp = [](auto &a, auto &b) { return a[0] > b[0]; };
	priority_queue<vector<int>, vector<vector<int>>, decltype(cmp)> pq(cmp);

	for (int i = 0, val; i < n; i++) {
		cin >> func[i][0] >> func[i][1] >> func[i][2];
		val = func[i][0] + func[i][1] + func[i][2];
		pq.push({ val, i, 1 });
	}

	vector<int> ans;
	while (m > 0) {
		auto arg = pq.top();
		pq.pop();

		int val = arg[0], id = arg[1], x = arg[2] + 1;
		ans.emplace_back(val);
		int a = func[id][0], b = func[id][1], c = func[id][2];
		val = a * x * x + b * x + c;
		pq.push({ val, id, x });
                m--;
	}

	for (auto val : ans) {
		cout << val << ' ';
	}
	cout << endl;
}

int main()
{
	int m, n;
	cin >> n >> m;

	method_tuple(n, m);
        //method_vector(n, m);

	return 0;
}